package com.knowledge.plus.泛型.demo;

import lombok.Data;

/**
 * 定义一个泛型类 GenericMinMaxPair，该类存储一对泛型类型的数据，并提供一个方法来获取最大值和最小值
 *
 * @author TPF
 * @since 2024/9/6
 */
@Data
class GenericMinMaxPair<T extends Comparable<T>> {

    private T value1;
    private T value2;

    public GenericMinMaxPair(T value1, T value2) {
        this.value1 = value1;
        this.value2 = value2;
    }

    private void test() {
        T max = this.value1.compareTo(value2) > 0 ? value1 : value2;
        T min = this.value1.compareTo(value2) < 0 ? value1 : value2;
        System.out.println("最大值：" + max + "，最小值：" + min);
    }

    public static void main(String[] args) {
        GenericMinMaxPair<Integer> pair = new GenericMinMaxPair<>(666, 888);
        pair.test();
    }

}
